package Thread.interrupt_thread;

///**
// *  Thread.interrupted() 判断当前线程是否被中断，若中断状态为true，清除中断标志
// */
//public class interrupt_inform {
//    private static class MyRUnnable implements Runnable{
//        @Override
//        public void run() {
//            for (int i = 0; i <5 ; i++) {
//                System.out.println(Thread.interrupted());
//            }
//        }
//    }
//
//    public static void main(String[] args) {
//        MyRUnnable m1=new MyRUnnable();
//        Thread thread=new Thread(m1);
//        thread.start();
//        thread.interrupt();
//    }
//}


/**
 *  Thread.currentThread().isInterrupted() 判断指定线程是否被中断
 *  不清除中断标志 这种方式通知收到的更及时，即使线程正在 sleep 也可以马上收到。
 */
public class interrupt_inform {
    private static class MyRUnnable implements Runnable{
        @Override
        public void run() {
            for (int i = 0; i <5 ; i++) {
                System.out.println(Thread.currentThread().isInterrupted());
            }
        }
    }

    public static void main(String[] args) {
        MyRUnnable m1=new MyRUnnable();
        Thread thread=new Thread(m1);
        thread.start();
        thread.interrupt();
    }
}